<?php
/**
 * @var \Phalcon\Mvc\View\Engine\Php $this
 */
?>
<!--  面包屑-->

<?=$this->elements->getMenu();?>

<?=$this->flashSession->output()?>

<?= $this->partial('layouts/pathtag')?>
<div id="success" style="display: none" class="alert alert-success alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <strong>删除成功!</strong>
</div>
<div id="error" style="display: none" class="alert alert-danger alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <strong>删除失败!</strong>
</div>
<hr/>
<?= $this->tag->linkTo(['index/store','class'=>"btn btn-primary ",'添 加'])?>
<br/>
<br/>
<table class="table table-condensed">
   <tr>
   <th>ID</th>
   <th>用户名</th>
   <th>邮箱</th>
   <th>添加时间</th>
   <th>操作</th>
   </tr>
   <!--循环数据--->
  <?php foreach ($data->items as $user):?>
  <tr id="user_<?=$user->id?>">
    <td><?=$user->id?></td>
    <td><?=$user->userName?></td>
    <td><?=$user->emai?></td>
    <td><?=date('Y-d-m H:i:s',$user->create_time)?></td>
    <td>
    <a href="<?= $this->url->get('index/edit',['id'=>$user->id])?>" class="btn btn-primary btn-xs" >编辑</a>
    <a href="#"  data="<?=$user->id?>" class="delete btn btn-danger btn-xs" >删除</a>
    </td>
  </tr>
 <?php endforeach; ?>
</table>

<nav>
    <ul class="pager">
        <li>
            <?= $this->tag->linkTo(["index/index?page=$data->before",'上一页'])?>
        </li>
        <li>
            <?= $this->tag->linkTo(["index/index?page=$data->next",'下一页'])?>
        </li>
    </ul>
</nav>

<script>
    $(function () {
        $('.delete').click(function () {
           var staus=confirm('是否删除');
            if(staus){
                var id=$(this).attr('data');
                var url="<?=$this->url->get('index/delete')?>";
               $.post(url,{'id':id},function (data) {
                   if(data){
                       $('#success').show();
                       var tr_id='user_'+data;
                       $('#'+tr_id).empty();


                   }else {
                       $('#error').show();
                   }
               })
            }
        });

    })

</script>